package com.androidvizlab.bachelor.customcomponents.listenersandadapters;

import com.androidvizlab.bachelor.R;
import com.androidvizlab.bachelor.Enums.SocketMessage;
import com.androidvizlab.bachelor.Interface.DataChangeEvent;
import com.androidvizlab.bachelor.Interface.Observer;
import com.androidvizlab.bachelor.Interface.SocketClientSimpleCallback;
import com.androidvizlab.bachelor.Views.EditOptionFileView;
import com.androidvizlab.bachelor.activities.EditOptionFileActivity;
import com.androidvizlab.bachelor.activities.ViewResultDataActivity;
import com.androidvizlab.bachelor.datamodels.VizlabInputData;
import com.androidvizlab.bachelor.datamodels.VizlabOutputData;
import com.androidvizlab.bachelor.datamodels.OptionsFileModel;
import com.androidvizlab.bachelor.utilities.NumberConverter;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;

/**
 * A custom listener that handles events liked button pressed, checkbox value changed etc...
 * This is the Controller in the MVC-pattern that the application follows. This is also acts
 * as the Observer in the Observer-Observable pattern between this listener class and the model.
 * Changes in values in the Model(Observable) notifies the Observer(CustomListener class) and
 * appropriate updates in the View(XML) is executed.
 * 
 * @author The Hive
 */
public class CustomListener implements OnClickListener, OnCheckedChangeListener,
 DialogInterface.OnClickListener,OnItemClickListener, Observer, SocketClientSimpleCallback{
	
	private EditOptionFileActivity editOptionFileActivity = null; //Main Activity for Editing options-file
	
	//*** MVC ***//
	private OptionsFileModel optionsFileModel = null; //Model: a object representation of the option-file
	private EditOptionFileView optionFileView = null; //View: a reference access to inflated views
	
	private VizlabInputData defaultOptionsFileData = null;
	
	private ViewResultDataActivity resultDataActivity = null;
	
	private CheckBox cb = null; //Arbitrary CheckBox variable
	private EditText et = null; //Arbitrary EditText variable
		
	public CustomListener()
	{
		
	}
	
	public CustomListener(EditOptionFileActivity editOptionFileActivity, OptionsFileModel optionFileModel,
			EditOptionFileView optionFileView)
	{
		this.editOptionFileActivity = editOptionFileActivity;
		this.optionsFileModel = optionFileModel;
		this.optionFileView = optionFileView;
	}
	
	/**
	 * Deals with click event triggered by the user
	 */
	@Override
	public void onClick(View v) 
	{
		int id = v.getId();
		
		if(v instanceof CheckBox)
		{
			cb = (CheckBox) v;
		}
		
		switch(id)
		{
		
		case R.id.btnAddNrCamera: //increase number of camera group
			optionsFileModel.addTripletCamGrp();
			break;
		
		case R.id.btnSubtractNrCamera: //decrease number of camera group
			optionsFileModel.subtractTripletCamGrp();
			break;
		
		case R.id.cbOutputSocket: //set program(in Vizlab) output to socket
			optionsFileModel.setProgramOutputSocketConnection(isChecked(cb));
			break;
		
		case R.id.btnSend: //Sends the settings data to the socket server
			
			sendData();

			break;
		
		case R.id.btnReset: //Set the value of Options file model to default
			setDefaultDataOnOptionsFileModel(defaultOptionsFileData);
			break;
			
		//Advanced options, Image File Input
		case R.id.cbImgFileInputTriplets:
			optionsFileModel.setImgFileInputTriplets(isChecked(cb));
			break;
			
		case R.id.cbImgFileInputTripletsTurnedRight:
			optionsFileModel.setImgFileInputTripletsTurnedRight(isChecked(cb));
			break;
		
		//Advanced options, Help file options
			
		case R.id.cbShowPointDetection:
			optionFileView.showPointDetectionOpts();//show/hide Point Detection options
			break;
			
		case R.id.cbShowImgFileInOpts:
			optionFileView.showImageFileInOpts(); //show/hide Image File Input options
			break;
		
		case R.id.cbShowImgFileOutOpts:
			optionFileView.showImageFileOutOpts(); //show/hide Image File Output options
			break;
		
		case R.id.cbShowHelpFile:
			optionFileView.showHelpFileOptions(); //show/hide Help file options
			break;
		
		case R.id.cbUseHelpFile:
			optionsFileModel.setCheckHelpFileValue(isChecked(cb));
			break;
			
			//ViewResultDataActivity
		case R.id.btnSendToProduction: //When the a camera group(s) are selected and the button is press to run a production
			
			Intent intent = new Intent(resultDataActivity,EditOptionFileActivity.class);
			
			Bundle extras = new Bundle();
			
			extras.putString("selected_tripcamgrps",resultDataActivity.getSelectedTripCamGrps());
			
			intent.putExtras(extras);
			
			resultDataActivity.startActivity(intent);
			break;
		}
	}

	/**
	 * Deals with changes in the selected radio button in a group
	 */
	@Override
	public void onCheckedChanged(RadioGroup group, int checkedId)
	{
		switch(checkedId)
		{
		case R.id.rbGeneral: //General tab/button is selected
			optionFileView.switchFragment(R.id.rbGeneral);
			break;
			
		case R.id.rbAdvanced: //Advanced tab/button is selected
			optionFileView.switchFragment(R.id.rbAdvanced);
			break;
			
		case R.id.rbCalibration: //Run type option (Calibration)
			optionsFileModel.setRunType(OptionsFileModel.RunType.CALIBRATION);
			break;
			
		case R.id.rbProduction: // Run type option (Production)
			optionsFileModel.setRunType(OptionsFileModel.RunType.PRODUCTION);
			break;
		
		//Advanced options, Image File input
		//case R.id.rbImgFileInputTriplets:
			//optionsFileModel.setImgFileInputTriplets(true);
			//break;
			
		//case R.id.rbImgFileInputTripletsTurnedRight:
			//optionsFileModel.setImgFileInputTripletsTurnedRight(true);
			//break;
			
		//Advanced options, Image File Output	
		case R.id.rbImgFileOutputOriginalImg:
			optionsFileModel.setImgFileOutputOriginalImg(true);
			break;
			
		case R.id.rbImgFileOutputGeneratedTriplets:
			optionsFileModel.setImgFileOutputGeneratedTriplets(true);
			break;
			
		case R.id.rbImgFileOutputGeneratedTripletsTurnedRight:
			optionsFileModel.setImgFileOutputGeneratedTripletsTurnedRight(true);
			break;
		}
	}
	
	//*** LISTVIEW - ONITEMCLICK LISTENER ***//
	/**
	 * Implementer method from the OnItemClickListener. This method determines
	 * which item on the list was click by the user.
	 */
	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
		getResultDataActivity().createCamInfoFragment(position);
		getResultDataActivity().setSelectedTripCamGrps1(position);
	}
	
	/**
	 * Method from DialogInterface.OnClickListener
	 * @param dialog
	 * @param which
	 */
	@Override
	public void onClick(DialogInterface dialog, int which) {
		dialog.dismiss();
	}
	
	/**
	 * Helper method: Determines if a CheckBox value is true or false
	 * 
	 * @param a reference to the CheckBox
	 * @return a boolean value.
	 */
	private boolean isChecked(CheckBox cb)
	{
		if(cb.isChecked())
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	
	//*** OBSERVER USE IN MVC PATTERN ***//
	
	/**
	 * This is use to observe an observable object in this case the model.
	 * Changes in the model will be cause the view to be updated.
	 */
	private boolean updateonce = false;
	@Override
	public void update(DataChangeEvent<?> e) {
				
		Handler handler = new Handler();
		handler.post(new Runnable(){
			
			@Override
			public void run() 
			{
				
				updateUI();	//Update Views(EditText, CheckBoxes, RadioButton, etc..)
				if(updateonce == false)
				updateOnceUI();
				updateonce = true;
			}
		});
	}

	/**
	 * Extra method form the Observer interface
	 */
	@Override
	public void update(DataChangeEvent<?> e, Object obj) {
		//Not implemented	
	}
	
	/**
	 * Update UI(Views). Set text, values and other UI related updates according
	 * to changes in the Model. This is used in conjunction with  Observer's update
	 * interface method. 
	 */
	public void updateUI()
	{
		//*** GENERAL ***//
		optionFileView.setNumTriCameraGroup(Integer.toString(optionsFileModel.getNumTripletCamGrp()));
		optionFileView.setCheckBoxValue(R.id.cbOutputSocket,optionsFileModel.isProgramOutputSocketConnection());
		optionFileView.showRunTypePathContainer(optionsFileModel.getRunType());
		//optionFileView.setCalibrationFilePath(optionsFileModel.getCalibrationFilePath());
		//optionFileView.setProductionFilePath(optionsFileModel.getCalibrationFileName());
		//optionFileView.setTriggingInterval(Integer.toString(optionsFileModel.getTriggingInterval()));
		//optionFileView.setTimePts(Integer.toString(optionsFileModel.getNumTimePts()));
		//optionFileView.setNumMarkers(Integer.toString(optionsFileModel.getNumMarkers()));
		
		//*** ADVANCED ***//
		
		//Point Detection
		//optionFileView.setPtsDetectionOffsetPixel(Integer.toString(optionsFileModel.getOffsetPix()));
		//optionFileView.setPtsDetectionMinPixel(Integer.toString(optionsFileModel.getMinpix()));
		//optionFileView.setPtsDetectionMaxPixel(Integer.toString(optionsFileModel.getMaxpix()));
		//optionFileView.setMinSep(Integer.toString(optionsFileModel.getMinsep()));
		//optionFileView.setMaxError(Integer.toString(optionsFileModel.getMaxerr()));
		
		//Image in/out-put
		//optionFileView.selectRadioButton(R.id.rbImgFileInputTriplets, optionsFileModel.isImgFileInputTriplets());
		//optionFileView.selectRadioButton(R.id.rbImgFileInputTripletsTurnedRight, optionsFileModel.isImgFileInputTripletsTurnedRight());
		optionFileView.setCheckBoxValue(R.id.cbImgFileInputTriplets, optionsFileModel.isImgFileInputTriplets());
		optionFileView.setCheckBoxValue(R.id.cbImgFileInputTripletsTurnedRight, optionsFileModel.isImgFileInputTripletsTurnedRight());
		optionFileView.selectRadioButton(R.id.rbImgFileOutputOriginalImg, optionsFileModel.isImgFileOutputOriginalImg());
		optionFileView.selectRadioButton(R.id.rbImgFileOutputGeneratedTriplets, optionsFileModel.isImgFileOutputGeneratedTriplets());
		optionFileView.selectRadioButton(R.id.rbImgFileOutputGeneratedTripletsTurnedRight, optionsFileModel.isImgFileOutputGeneratedTripletsTurnedRight());
		
		//Help file
		optionFileView.setCheckBoxValue(R.id.cbHelpFileSeqData, optionsFileModel.isHelpFileOutputImageDetectPoints());
		optionFileView.setCheckBoxValue(R.id.cbHelpFileImgDetectPtsOutput,optionsFileModel.isHelpFileOutputImageDetectPoints());
		optionFileView.setCheckBoxValue(R.id.cbHelpFileDupPtsOutput,optionsFileModel.isHelpFileOutputDuplicatePoints());
		
		optionFileView.setCheckBoxValue(R.id.cbHelpFileMatch, optionsFileModel.isHelpFileOutputMatch3());
		optionFileView.setCheckBoxValue(R.id.cbHelpFileMatch3Output,optionsFileModel.isHelpFileOutputMatch3());
		optionFileView.setCheckBoxValue(R.id.cbHelpFileDobbelMatchOutput,optionsFileModel.isHelpFileOutputdobbelMatch());
		optionFileView.setCheckBoxValue(R.id.cbHelpFileConnectionPtsOutput,optionsFileModel.isHelpFileOutputConnectPoints());
		optionFileView.setCheckBoxValue(R.id.cbHelpFileTimeSeriesOutput,optionsFileModel.isHelpFileOutputTimeseries());
		
		optionFileView.setCheckBoxValue(R.id.cbUseHelpFile, optionsFileModel.getCheckHelpFileValue());
		//optionFileView.setApproxFrameMarkerLimit(Double.toString(optionsFileModel.getApproxFrameMarkerLimit()));
	}
	
	public void updateOnceUI()
	{
		//*** GENERAL ***//
		optionFileView.setNumTriCameraGroup(Integer.toString(optionsFileModel.getNumTripletCamGrp()));
		optionFileView.setCheckBoxValue(R.id.cbOutputSocket,optionsFileModel.isProgramOutputSocketConnection());
		optionFileView.showRunTypePathContainer(optionsFileModel.getRunType());
		optionFileView.setCalibrationFilePath(optionsFileModel.getCalibrationFilePath());
		optionFileView.setProductionFilePath(optionsFileModel.getCalibrationFileName());
		optionFileView.setTriggingInterval(Integer.toString(optionsFileModel.getTriggingInterval()));
		optionFileView.setTimePts(Integer.toString(optionsFileModel.getNumTimePts()));
		optionFileView.setNumMarkers(Integer.toString(optionsFileModel.getNumMarkers()));
		
		//*** ADVANCED ***//
		
		//Point Detection
		optionFileView.setPtsDetectionOffsetPixel(Integer.toString(optionsFileModel.getOffsetPix()));
		optionFileView.setPtsDetectionMinPixel(Integer.toString(optionsFileModel.getMinpix()));
		optionFileView.setPtsDetectionMaxPixel(Integer.toString(optionsFileModel.getMaxpix()));
		optionFileView.setMinSep(Integer.toString(optionsFileModel.getMinsep()));
		optionFileView.setMaxError(Integer.toString(optionsFileModel.getMaxerr()));
		
		//Image in/out-put
		//optionFileView.selectRadioButton(R.id.rbImgFileInputTriplets, optionsFileModel.isImgFileInputTriplets());
		//optionFileView.selectRadioButton(R.id.rbImgFileInputTripletsTurnedRight, optionsFileModel.isImgFileInputTripletsTurnedRight());
		
		optionFileView.setCheckBoxValue(R.id.cbImgFileInputTriplets, optionsFileModel.isImgFileInputTriplets());
		optionFileView.setCheckBoxValue(R.id.cbImgFileInputTripletsTurnedRight, optionsFileModel.isImgFileInputTripletsTurnedRight());
				
		optionFileView.selectRadioButton(R.id.rbImgFileOutputOriginalImg, optionsFileModel.isImgFileOutputOriginalImg());
		optionFileView.selectRadioButton(R.id.rbImgFileOutputGeneratedTriplets, optionsFileModel.isImgFileOutputGeneratedTriplets());
		optionFileView.selectRadioButton(R.id.rbImgFileOutputGeneratedTripletsTurnedRight, optionsFileModel.isImgFileOutputGeneratedTripletsTurnedRight());
		
		//Help file
		optionFileView.setCheckBoxValue(R.id.cbHelpFileSeqData, optionsFileModel.isHelpFileOutputImageDetectPoints());
		optionFileView.setCheckBoxValue(R.id.cbHelpFileImgDetectPtsOutput,optionsFileModel.isHelpFileOutputImageDetectPoints());
		optionFileView.setCheckBoxValue(R.id.cbHelpFileDupPtsOutput,optionsFileModel.isHelpFileOutputDuplicatePoints());
		
		optionFileView.setCheckBoxValue(R.id.cbHelpFileMatch, optionsFileModel.isHelpFileOutputMatch3());
		optionFileView.setCheckBoxValue(R.id.cbHelpFileMatch3Output,optionsFileModel.isHelpFileOutputMatch3());
		optionFileView.setCheckBoxValue(R.id.cbHelpFileDobbelMatchOutput,optionsFileModel.isHelpFileOutputdobbelMatch());
		optionFileView.setCheckBoxValue(R.id.cbHelpFileConnectionPtsOutput,optionsFileModel.isHelpFileOutputConnectPoints());
		optionFileView.setCheckBoxValue(R.id.cbHelpFileTimeSeriesOutput,optionsFileModel.isHelpFileOutputTimeseries());
		
		optionFileView.setCheckBoxValue(R.id.cbUseHelpFile, optionsFileModel.getCheckHelpFileValue());
		
		//optionFileView.setApproxFrameMarkerLimit(Double.toString(optionsFileModel.getApproxFrameMarkerLimit()));
	}
	
	//*** SOCKET CLIENT CALLBACK HANDLER ***//
	
	/**
	 * Listening for incoming data from server.
	 * This is a part of the Interface in the ActivitySocketClient.class
	 * that enables us to retrieved from the background process and Activities.
	 */
	@Override
	public void onDataReceived(Object object) 
	{
		if(object instanceof SocketMessage)
		{
			SocketMessage msg = (SocketMessage) object; // get the value of the message
			
			if(msg == SocketMessage.PROCESS_STARTED) //msg = PROCESS_STARTED
			{
				//Start the MQTT Data Push Service and register to a topic.
				//The user will be notify by notifications on the status bar.
				//Once the server publishes on the topic and the service receives
				//the message, the user then can click on the notification and view
				//the result(ViewResultDataActivity.class will be started and retrieve the
				//actual data to be viewed). All notifications and service will be cleared
				//once the result is displayed.
				getEditOptionFileActivity().startDataPushService();
			}
		}
		else if(object instanceof VizlabInputData)
		{
			defaultOptionsFileData = (VizlabInputData) object;
			
			this.editOptionFileActivity.runOnUiThread(new Runnable(){

				@Override
				public void run() 
				{
					setDefaultDataOnOptionsFileModel(defaultOptionsFileData);	
				}
				
			});
		}
		else if(object instanceof VizlabOutputData)
		{
			//This is the data to be displayed once the service receives the published
			//message from the server.
			
			resultDataActivity.updateDataList(((VizlabOutputData)object).getListCamGrp());
			Log.i("viz_result_data","data received:onDataReceived");
		}
	}
	
	//Set default data on Options file model
	/**
	 * Set the default values from the retrieved options-file
	 * @param input an object containing values from the options-file
	 */
	public void setDefaultDataOnOptionsFileModel(VizlabInputData input)
	{
		if(input != null){
			//GENERAL OPTIONS
			optionsFileModel.setCalibrationFilePath(input.getCalibrationFilePath());
			optionsFileModel.setCalibrationFileName(input.getCalibrationFileName());
			optionsFileModel.setRunType(input.getRunType());
			optionsFileModel.setTriggingInterval(input.getTriggingInterval());
			optionsFileModel.setNumTripletCamGrp(input.getNumTripletCamGrp());
			optionsFileModel.setNumTimePts(input.getNumTimePts());
			optionsFileModel.setNumMarkers(input.getNumMarkers());
						
			optionsFileModel.setProgramOutputSocketConnection(input.getProgramOutputSocketConnection());
			
			//ADVANCED OPTIONS
			
			//Point Detection
			optionsFileModel.setOffsetPix(input.getOffsetPix());
			optionsFileModel.setMinpix(input.getMinpix());
			optionsFileModel.setMaxpix(input.getMaxpix());
			optionsFileModel.setMinsep(input.getMinsep());
			optionsFileModel.setMaxerr(input.getMaxerr());
			
			//Image file in/output
			optionsFileModel.setImgFileInputTriplets(input.getImgFileInputTriplets());	
			
			optionsFileModel.setImgFileInputTripletsTurnedRight(input.getImgFileInputTripletsTurnedRight());	
			
			optionsFileModel.setImgFileOutputOriginalImg(input.getImgFileOutputOriginalImg());	
			
			optionsFileModel.setImgFileOutputGeneratedTriplets(input.getImgFileOutputGeneratedTriplets());	
			
			optionsFileModel.setImgFileOutputGeneratedTripletsTurnedRight(input.getImgFileOutputGeneratedTripletsTurnedRight());		
			
			//Help file
			
			optionsFileModel.setHelpFileOutputImageDetectPoints(input.getHelpFileOutputImageDetectPoints());	
			
			optionsFileModel.setHelpFileOutputDuplicatePoints(input.getHelpFileOutputDuplicatePoints());
			
			optionsFileModel.setHelpFileOutputMatch3(input.getHelpFileOutputMatch3());	
			
			optionsFileModel.setHelpFileOutputdobbelMatch(input.getHelpFileOutputdobbelMatch());	
			
			optionsFileModel.setHelpFileOutputConnectPoints(input.getHelpFileOutputConnectPoints());		
			
			optionsFileModel.setHelpFileOutputTimeseries(input.getHelpFileOutputTimeseries());			
				
			//optionsFileModel.setApproxFrameMarkerLimit(input.getApproxFrameMarkerLimit());
		}
	}
	
	//*** SEND VizlabInputData ***//
	/**
	 * Used to send data to the server application using socket connection
	 */
	public void sendData()
	{
		optionsFileModel.setCalibrationFilePath(optionFileView.getCalibrationFilePath());
		optionsFileModel.setCalibrationFileName(optionFileView.getProductionFilePath());
		optionsFileModel.setNumTripletCamGrp(NumberConverter.convertToInt(optionFileView.getNumTriCameraGroup(), 1));
		optionsFileModel.setNumTimePts(NumberConverter.convertToInt(optionFileView.getNumTimePts(), 1));
		optionsFileModel.setNumMarkers(NumberConverter.convertToInt(optionFileView.getNumMarkers(), 3));
		optionsFileModel.setTriggingInterval(NumberConverter.convertToInt(optionFileView.getTriggingInterval(), 1));
		
		optionsFileModel.setMinpix(NumberConverter.convertToInt(optionFileView.getPtsDetectionMinPixel(), 1));
		optionsFileModel.setMaxpix(NumberConverter.convertToInt(optionFileView.getPtsDetectionMaxPixel(),1));
		optionsFileModel.setOffsetPix(NumberConverter.convertToInt(optionFileView.getPtsDetectionOffsetPixel(), 1));
		optionsFileModel.setMinsep(NumberConverter.convertToInt(optionFileView.getMinSep(), 1));
		optionsFileModel.setMaxerr(NumberConverter.convertToInt(optionFileView.getMaxError(), 1));
		
		
		if(isValidData())
		{
			
			this.editOptionFileActivity.sendDataToSocketServer(optionsFileModel.sendData());
		}
	}
	
	/**
	 * Checks if the data is valid
	 * @return boolean value true/false depending on the validity of each field. 
	 */
	public boolean isValidData()
	{
		if(optionFileView.getCalibrationFilePath() == null || 
				optionFileView.getCalibrationFilePath().equals(""))
		{
			optionFileView.setErrorFieldError(R.id.etFilePathCalibration, "Field required");
			
			return false;
		}
		
		if(optionFileView.getProductionFilePath() == null || 
				optionFileView.getProductionFilePath().equals(""))
		{
			optionFileView.setErrorFieldError(R.id.etFilePathProduction, "Field required");
			
			return false;
		}
		
		if(optionFileView.getTriggingInterval() == null || 
				optionFileView.getTriggingInterval().equals(""))
		{
			optionFileView.setErrorFieldError(R.id.etTriggingInterval, "Field required");
			
			return false;
		}
		else if(NumberConverter.convertToInt(optionFileView.getTriggingInterval(),-1) < 0)
		{
			optionFileView.setErrorFieldError(R.id.etTriggingInterval, "Whole number required");
			
			return false;
		}
		
		if(optionFileView.getNumTriCameraGroup() == null || 
				optionFileView.getNumTriCameraGroup().equals(""))
		{
			optionFileView.setErrorFieldError(R.id.etNrCameras, "Field required");
			
			return false;
		}
		else if(NumberConverter.convertToInt(optionFileView.getNumTriCameraGroup(),-1) < 0)
		{
			optionFileView.setErrorFieldError(R.id.etNrCameras, "Whole number required");
			
			return false;
		}
		
		if(optionFileView.getNumTimePts() == null || 
				optionFileView.getNumTimePts().equals(""))
		{
			optionFileView.setErrorFieldError(R.id.etNrTimePts, "Field required");
			
			return false;
		}
		else if(NumberConverter.convertToInt(optionFileView.getNumTimePts(),-1) < 0)
		{
			optionFileView.setErrorFieldError(R.id.etNrTimePts, "Whole number required");
			
			return false;
		}
		
		if(optionFileView.getNumMarkers() == null || 
				optionFileView.getNumMarkers().equals(""))
		{
			optionFileView.setErrorFieldError(R.id.etNrMarkers, "Field required");
			
			return false;
		}
		else if(NumberConverter.convertToInt(optionFileView.getNumMarkers(),-1) < 0)
		{
			optionFileView.setErrorFieldError(R.id.etNrMarkers, "Whole number required");
			
			return false;
		}
		
		if(optionFileView.getPtsDetectionOffsetPixel() == null || 
				optionFileView.getPtsDetectionOffsetPixel().equals(""))
		{
			optionFileView.setErrorFieldError(R.id.etPtsDetectionOffsetPx, "Field required");
			
			return false;
		}
		else if(NumberConverter.convertToInt(optionFileView.getPtsDetectionOffsetPixel(),-1) < 0)
		{
			optionFileView.setErrorFieldError(R.id.etPtsDetectionOffsetPx, "Whole number required");
			
			return false;
		}
		
		if(optionFileView.getPtsDetectionMinPixel() == null || 
				optionFileView.getPtsDetectionMinPixel().equals(""))
		{
			optionFileView.setErrorFieldError(R.id.etPtsDetectionMinPx, "Field required");
			
			return false;
		}
		else if(NumberConverter.convertToInt(optionFileView.getPtsDetectionMinPixel(),-1) < 0)
		{
			optionFileView.setErrorFieldError(R.id.etPtsDetectionMinPx, "Whole number required");
			
			return false;
		}
		
		if(optionFileView.getPtsDetectionMaxPixel() == null || 
				optionFileView.getPtsDetectionMaxPixel().equals(""))
		{
			optionFileView.setErrorFieldError(R.id.etPtsDetectionMaxPx, "Field required");
			
			return false;
		}
		else if(NumberConverter.convertToInt(optionFileView.getPtsDetectionMaxPixel(),-1) < 0)
		{
			optionFileView.setErrorFieldError(R.id.etPtsDetectionMaxPx, "Whole number required");
			
			return false;
		}
		
		if(optionFileView.getMinSep() == null || 
				optionFileView.getMinSep().equals(""))
		{
			optionFileView.setErrorFieldError(R.id.etMinsep, "Field required");
			
			return false;
		}
		else if(NumberConverter.convertToInt(optionFileView.getMinSep(),-1) < 0)
		{
			optionFileView.setErrorFieldError(R.id.etMinsep, "Whole number required");
			
			return false;
		}
		
		if(optionFileView.getMaxError() == null || 
				optionFileView.getMaxError().equals(""))
		{
			optionFileView.setErrorFieldError(R.id.etMaxErr, "Field required");
			
			return false;
		}
		else if(NumberConverter.convertToInt(optionFileView.getMaxError(),-1) < 0)
		{
			optionFileView.setErrorFieldError(R.id.etMaxErr, "Whole number required");
			
			return false;
		}
		
		return true;
	}

	//*** GETTER AND SETTERS ***//
	
	public EditOptionFileActivity getEditOptionFileActivity() {
		return editOptionFileActivity;
	}

	public void setEditOptionFileActivity(
			EditOptionFileActivity editOptionFileActivity) {
		this.editOptionFileActivity = editOptionFileActivity;
	}

	public OptionsFileModel getOptionFileModel() {
		return optionsFileModel;
	}

	public void setOptionFileModel(OptionsFileModel optionFileModel) {
		this.optionsFileModel = optionFileModel;
	}

	public ViewResultDataActivity getResultDataActivity() {
		return resultDataActivity;
	}

	public void setResultDataActivity(ViewResultDataActivity resultDataActivity) {
		this.resultDataActivity = resultDataActivity;
	}

	public VizlabInputData getDefaultOptionsFileData() {
		return defaultOptionsFileData;
	}

	public void setDefaultOptionsFileData(VizlabInputData defaultOptionsFileData) {
		this.defaultOptionsFileData = defaultOptionsFileData;
	}

	public EditOptionFileView getOptionFileView() {
		return optionFileView;
	}

	public void setOptionFileView(EditOptionFileView optionFileView) {
		this.optionFileView = optionFileView;
	}
}